package com.dotndot.view.activity;

import java.util.Calendar;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Handler;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.dotndot.R;
import com.dotndot.view.list.BasicListAdapter;


public class UserInfoView
{
    private Context context;
    private View rootView;
    private ListView babyListView;
    private BasicListAdapter babyListAdapter;
    private LinearLayout addBabyLayout;
    private ImageView userInfoDownImg;
    private int tempBabyGenderIndex = 0, babyGenderIndex = 0;
    private EditText babyName;
    private TextView babyGender, babyBirthday;
    private Calendar babyBirthdayCal;
    private ImageView babyAvatar;
    private Bitmap babyAvatarBitmap;
    private final int GET_GALLERY_AVATAR = 0;
    
    
    public UserInfoView(Context context, View rootView){
        this.context = context;
        this.rootView = rootView;
    }
    
    public void viewInit(){
        
        babyListView =  (ListView) rootView.findViewById(R.id.baby_list);
        babyListAdapter = new BasicListAdapter(context);
        babyListView.setAdapter(babyListAdapter);
        
    }
    
    private void initAddBabyView(){
        
        addBabyLayout = (LinearLayout)rootView.findViewById(R.id.user_info_add_baby_layout);
        userInfoDownImg = (ImageView)rootView.findViewById(R.id.user_info_down_img);
        
        babyAvatar = (ImageView)addBabyLayout.findViewById(R.id.user_info_avatar);
        babyAvatar.setOnClickListener(new View.OnClickListener()
        {            
            @Override
            public void onClick( View v )
            {
//                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
//                intent.setType("image/*");
//                intent.putExtra("crop", "true");
//                intent.putExtra("outputX", 100);
//                intent.putExtra("outputY", 100);
//                intent.putExtra("aspectX", 1);
//                intent.putExtra("aspectY", 1);
//                intent.putExtra("scale", true);
//                intent.putExtra("return-data", true);
//                startActivityForResult(intent, GET_GALLERY_AVATAR);                
            } 
        });
        
        babyName = (EditText)addBabyLayout.findViewById(R.id.user_info_baby_name);
        babyGender = (TextView)addBabyLayout.findViewById(R.id.user_info_baby_gender);
        babyGender.setOnClickListener(new View.OnClickListener()
        {            
            @Override
            public void onClick( View v )
            {
//                showDialog(POPUP_BABY_GENDER);
            }
        });
        babyBirthday = (TextView)addBabyLayout.findViewById(R.id.user_info_baby_birthday);
        babyBirthday.setOnClickListener(new View.OnClickListener()
        {            
            @Override
            public void onClick( View v )
            {
//                showDialog(POPUP_BABY_BIRTHDAY);
            }
        });

//        ((RelativeLayout)userLayout.findViewById(R.id.user_info_down_layout)).setOnClickListener(new View.OnClickListener()
//        {            
//            @Override
//            public void onClick( View v )
//            {
//                if(addBabyLayout.getVisibility() == View.GONE){
//                    addBabyLayout.setVisibility(View.VISIBLE);
//                    babyName.setText("");
//                    babyGender.setText("");
//                    babyBirthday.setText("");
//                    babyAvatarBitmap = null;
//                    babyAvatar.setBackgroundResource(R.drawable.gnb_pic_big_bg);
//                    userInfoDownImg.setBackgroundResource(R.drawable.gnb_baby_up);
//                }else{
//                    addBabyLayout.setVisibility(View.GONE);
//                    userInfoDownImg.setBackgroundResource(R.drawable.gnb_baby_down);
//                }
//            }
//        });
        
//        ((Button)userLayout.findViewById(R.id.user_info_add_baby_btn)).setOnClickListener(new View.OnClickListener()
//        {
//            @Override
//            public void onClick( View v )
//            {
//                addBaby();
//            }            
//        });
    }    
    
    private void addBaby(){
//        String momIndex = momApp.getUserInfo().getUserIndex();
//        String name = babyName.getText().toString();
//        String gender = babyGender.getText().toString(); 
//        String birthday = babyBirthday.getText().toString();
//        
//        if(name.equals("")){
//            BaseDialog.getIns().showDialog(MomLauncher.this, R.string.noti_user_info_add_baby_name);
//        }                
//        else if(gender.equals("")){
//            BaseDialog.getIns().showDialog(MomLauncher.this, R.string.noti_user_info_add_baby_gender);
//        }                
//        else if(birthday.equals("")){
//            BaseDialog.getIns().showDialog(MomLauncher.this, R.string.noti_user_info_add_baby_birthday);
//        }    
//        else{
//            SendServerParam param = new SendServerParam(REQUEST.BABY_ADD_API);
//            param.put(BABY.momIndex, momIndex);
//            param.put(BABY.name, name);
//            param.put(BABY.gender, gender);
//            param.put(BABY.birthday, birthday);
//            param.putBitmap(BABY.avatar, babyAvatarBitmap);
//            requestNetwork(param);
//        }
    }    
    Handler send = new Handler(){
        
    };
}
